<?php
/**
 * Created by PhpStorm.
 * User: VJLau
 * Date: 2018/2/5
 * Time: 下午12:29
 */

$adult_number = intval($_GPC['adult_number']);
$child_number = intval($_GPC['child_number']);
$index = intval($_GPC['index']);
$type = trim($_GPC['type']);
$member = unserialize(base64_decode($_SESSION['vj_member']));
$insurance_id = intval($_GPC['insurance_id']);
$start_day = $_GPC['start_day'];
$finish_day = $_GPC['finish_day'];
$op = empty($_GPC['op']) ? 'list' : $_GPC['op'];
if ($op == 'list') {
    $insureds = pdo_fetchall("SELECT * FROM " . tablename('bontrip_insurance_member')
        . " WHERE member_id = {$member['id']} AND uniacid = {$uniacid} AND deleted_at is null");

    $title = '选择被保人';
    include $this->template('insured');
} else if ($op == 'post') {
    $id = intval($_GPC['id']);
    if ($_POST) {
        $data = array(
            'uniacid' => $uniacid,
            'member_id' => $member['id'],
            'certificate_type' => ($_GPC['certificate_type'] == '护照') ? 1 : 2,
            'certificate_no' => trim($_GPC['certificate_no']),
            'real_name' => trim($_GPC['real_name']),
            'updated_at' => TIMESTAMP
        );

        if (!empty($id)) {
            pdo_update('bontrip_insurance_member', $data, array('id' => $id));
        } else {
            $data['created_at'] = $data['updated_at'];
            pdo_insert('bontrip_insurance_member', $data);
        }
        message('保存被保人成功！', url('entry', array('m' => 'vj_bontrip', 'do' => 'insured', 'adult_number' => $adult_number, 'child_number' => $child_number,'insurance_id' => $insurance_id, 'start_day' => $start_day, 'finish_day' => $finish_day, 'index' => $index, 'type' => $type), true), 'success');
    }
    if (!empty($id)) {
        $insured = pdo_fetch("SELECT * FROM" . tablename('bontrip_insurance_member')
            . " WHERE member_id = {$member['id']} AND uniacid = {$uniacid} AND id = {$id} AND deleted_at is null");
        $title = '编辑被保人';
    } else {
        $title = '新增被保人';
    }
    include $this->template('insured_post');
}



